from building import *

cwd  = GetCurrentDir()

src_pub = []
src_lib = []
path = []

sys_config = os.path.join(cwd, '..', '..', '..', 'config', 'sys_config.h')
options = LocalOptions(sys_config)

ble_lib_name = 'ble'
platform_match = 'yes'

if (GetLocalDepend(options, 'CFG_SOC_NAME') == 'SOC_BK7231N'):
    ble_lib_name += '_7231n'
elif (GetLocalDepend(options, 'CFG_SOC_NAME') == 'SOC_BK7236'):
    ble_lib_name += '_7236'
else:
    ble_lib_name += '_unknown'
    platform_match = 'no'

if (GetLocalDepend(options, 'CFG_USE_BLE_PS') == 1):
    ble_lib_name += '_ps'

if ((GetLocalDepend(options, 'CFG_SUPPORT_BLE') == 1)
    and (GetLocalDepend(options, 'CFG_BLE_VERSION') == 'BLE_VERSION_5_x')):
    src_lib += ["ble_lib/ip/ble/hl/src/gap/gapc/gapc.c"]
    src_lib += ["ble_lib/ip/ble/hl/src/gap/gapc/gapc_cte.c"]
    src_lib += ["ble_lib/ip/ble/hl/src/gap/gapc/gapc_hci.c"]
    src_lib += ["ble_lib/ip/ble/hl/src/gap/gapc/gapc_past.c"]
    src_lib += ["ble_lib/ip/ble/hl/src/gap/gapc/gapc_sig.c"]
    src_lib += ["ble_lib/ip/ble/hl/src/gap/gapc/gapc_smp.c"]
    src_lib += ["ble_lib/ip/ble/hl/src/gap/gapc/gapc_task.c"]
    src_lib += ["ble_lib/ip/ble/hl/src/gap/gapm/gapm.c"]
    src_lib += ["ble_lib/ip/ble/hl/src/gap/gapm/gapm_actv.c"]
    src_lib += ["ble_lib/ip/ble/hl/src/gap/gapm/gapm_addr.c"]
    src_lib += ["ble_lib/ip/ble/hl/src/gap/gapm/gapm_adv.c"]
    src_lib += ["ble_lib/ip/ble/hl/src/gap/gapm/gapm_cfg.c"]
    src_lib += ["ble_lib/ip/ble/hl/src/gap/gapm/gapm_init.c"]
    src_lib += ["ble_lib/ip/ble/hl/src/gap/gapm/gapm_list.c"]
    src_lib += ["ble_lib/ip/ble/hl/src/gap/gapm/gapm_per_sync.c"]
    src_lib += ["ble_lib/ip/ble/hl/src/gap/gapm/gapm_scan.c"]
    src_lib += ["ble_lib/ip/ble/hl/src/gap/gapm/gapm_smp.c"]
    src_lib += ["ble_lib/ip/ble/hl/src/gap/gapm/gapm_task.c"]
    src_lib += ["ble_lib/ip/ble/hl/src/gatt/attc/attc.c"]
    src_lib += ["ble_lib/ip/ble/hl/src/gatt/attm/attm.c"]
    src_lib += ["ble_lib/ip/ble/hl/src/gatt/attm/attm_db.c"]
    src_lib += ["ble_lib/ip/ble/hl/src/gatt/atts/atts.c"]
    src_lib += ["ble_lib/ip/ble/hl/src/gatt/gattc/gattc.c"]
    src_lib += ["ble_lib/ip/ble/hl/src/gatt/gattc/gattc_rc.c"]
    src_lib += ["ble_lib/ip/ble/hl/src/gatt/gattc/gattc_sdp.c"]
    src_lib += ["ble_lib/ip/ble/hl/src/gatt/gattc/gattc_svc.c"]
    src_lib += ["ble_lib/ip/ble/hl/src/gatt/gattc/gattc_task.c"]
    src_lib += ["ble_lib/ip/ble/hl/src/gatt/gattm/gattm.c"]
    src_lib += ["ble_lib/ip/ble/hl/src/gatt/gattm/gattm_task.c"]
    src_lib += ["ble_lib/ip/ble/hl/src/l2c/l2cc/l2cc.c"]
    src_lib += ["ble_lib/ip/ble/hl/src/l2c/l2cc/l2cc_lecb.c"]
    src_lib += ["ble_lib/ip/ble/hl/src/l2c/l2cc/l2cc_pdu.c"]
    src_lib += ["ble_lib/ip/ble/hl/src/l2c/l2cc/l2cc_sig.c"]
    src_lib += ["ble_lib/ip/ble/hl/src/l2c/l2cc/l2cc_task.c"]
    src_lib += ["ble_lib/ip/ble/hl/src/l2c/l2cm/l2cm.c"]
    src_lib += ["ble_lib/ip/ble/hl/src/rwble_hl/rwble_hl.c"]
    src_lib += ["ble_lib/ip/ble/ll/src/co/ble_util_buf.c"]
    src_lib += ["ble_lib/ip/ble/ll/src/llc/llc.c"]
    src_lib += ["ble_lib/ip/ble/ll/src/llc/llc_chmap_upd.c"]
    src_lib += ["ble_lib/ip/ble/ll/src/llc/llc_clk_acc.c"]
    src_lib += ["ble_lib/ip/ble/ll/src/llc/llc_con_upd.c"]
    src_lib += ["ble_lib/ip/ble/ll/src/llc/llc_cte.c"]
    src_lib += ["ble_lib/ip/ble/ll/src/llc/llc_dbg.c"]
    src_lib += ["ble_lib/ip/ble/ll/src/llc/llc_disconnect.c"]
    src_lib += ["ble_lib/ip/ble/ll/src/llc/llc_dl_upd.c"]
    src_lib += ["ble_lib/ip/ble/ll/src/llc/llc_encrypt.c"]
    src_lib += ["ble_lib/ip/ble/ll/src/llc/llc_feat_exch.c"]
    src_lib += ["ble_lib/ip/ble/ll/src/llc/llc_hci.c"]
    src_lib += ["ble_lib/ip/ble/ll/src/llc/llc_le_ping.c"]
    src_lib += ["ble_lib/ip/ble/ll/src/llc/llc_llcp.c"]
    src_lib += ["ble_lib/ip/ble/ll/src/llc/llc_past.c"]
    src_lib += ["ble_lib/ip/ble/ll/src/llc/llc_phy_upd.c"]
    src_lib += ["ble_lib/ip/ble/ll/src/llc/llc_task.c"]
    src_lib += ["ble_lib/ip/ble/ll/src/llc/llc_ver_exch.c"]
    src_lib += ["ble_lib/ip/ble/ll/src/lld/lld.c"]
    src_lib += ["ble_lib/ip/ble/ll/src/lld/lld_adv.c"]
    src_lib += ["ble_lib/ip/ble/ll/src/lld/lld_con.c"]
    src_lib += ["ble_lib/ip/ble/ll/src/lld/lld_init.c"]
    src_lib += ["ble_lib/ip/ble/ll/src/lld/lld_per_adv.c"]
    src_lib += ["ble_lib/ip/ble/ll/src/lld/lld_scan.c"]
    src_lib += ["ble_lib/ip/ble/ll/src/lld/lld_sync.c"]
    src_lib += ["ble_lib/ip/ble/ll/src/lld/lld_test.c"]
    src_lib += ["ble_lib/ip/ble/ll/src/llm/llm.c"]
    src_lib += ["ble_lib/ip/ble/ll/src/llm/llm_adv.c"]
    src_lib += ["ble_lib/ip/ble/ll/src/llm/llm_hci.c"]
    src_lib += ["ble_lib/ip/ble/ll/src/llm/llm_init.c"]
    src_lib += ["ble_lib/ip/ble/ll/src/llm/llm_scan.c"]
    src_lib += ["ble_lib/ip/ble/ll/src/llm/llm_task.c"]
    src_lib += ["ble_lib/ip/ble/ll/src/llm/llm_test.c"]
    src_lib += ["ble_lib/ip/hci/src/hci.c"]
    src_lib += ["ble_lib/ip/hci/src/hci_fc.c"]
    src_lib += ["ble_lib/ip/hci/src/hci_msg.c"]
    src_lib += ["ble_lib/ip/hci/src/hci_tl.c"]
    src_lib += ["ble_lib/ip/sch/src/sch_alarm.c"]
    src_lib += ["ble_lib/ip/sch/src/sch_arb.c"]
    src_lib += ["ble_lib/ip/sch/src/sch_plan.c"]
    src_lib += ["ble_lib/ip/sch/src/sch_prog.c"]
    src_lib += ["ble_lib/ip/sch/src/sch_slice.c"]
    src_lib += ["ble_lib/modules/aes/src/ble_aes.c"]
    src_lib += ["ble_lib/modules/aes/src/ble_aes_c1.c"]
    src_lib += ["ble_lib/modules/aes/src/ble_aes_ccm.c"]
    src_lib += ["ble_lib/modules/aes/src/ble_aes_cmac.c"]
    src_lib += ["ble_lib/modules/aes/src/ble_aes_f4.c"]
    src_lib += ["ble_lib/modules/aes/src/ble_aes_f5.c"]
    src_lib += ["ble_lib/modules/aes/src/ble_aes_f6.c"]
    src_lib += ["ble_lib/modules/aes/src/ble_aes_g2.c"]
    src_lib += ["ble_lib/modules/aes/src/ble_aes_k1.c"]
    src_lib += ["ble_lib/modules/aes/src/ble_aes_k2.c"]
    src_lib += ["ble_lib/modules/aes/src/ble_aes_k3.c"]
    src_lib += ["ble_lib/modules/aes/src/ble_aes_k4.c"]
    src_lib += ["ble_lib/modules/aes/src/ble_aes_rpa.c"]
    src_lib += ["ble_lib/modules/aes/src/ble_aes_s1.c"]
    src_lib += ["ble_lib/modules/common/src/common_list.c"]
    src_lib += ["ble_lib/modules/common/src/common_utils.c"]
    src_lib += ["ble_lib/modules/dbg/src/dbg.c"]
    src_lib += ["ble_lib/modules/dbg/src/dbg_iqgen.c"]
    src_lib += ["ble_lib/modules/dbg/src/dbg_mwsgen.c"]
    src_lib += ["ble_lib/modules/dbg/src/dbg_swdiag.c"]
    src_lib += ["ble_lib/modules/dbg/src/dbg_task.c"]
    src_lib += ["ble_lib/modules/dbg/src/dbg_trc.c"]
    src_lib += ["ble_lib/modules/dbg/src/dbg_trc_mem.c"]
    src_lib += ["ble_lib/modules/dbg/src/dbg_trc_tl.c"]
    src_lib += ["ble_lib/modules/ecc_p256/src/ecc_p256.c"]
    src_lib += ["ble_lib/modules/h4tl/src/h4tl.c"]
    src_lib += ["ble_lib/modules/ke/src/kernel.c"]
    src_lib += ["ble_lib/modules/ke/src/kernel_event.c"]
    src_lib += ["ble_lib/modules/ke/src/kernel_mem.c"]
    src_lib += ["ble_lib/modules/ke/src/kernel_msg.c"]
    src_lib += ["ble_lib/modules/ke/src/kernel_queue.c"]
    src_lib += ["ble_lib/modules/ke/src/kernel_task.c"]
    src_lib += ["ble_lib/modules/ke/src/kernel_timer.c"]
    src_lib += ["ble_lib/modules/rwip/rwip_driver.c"]

    src_pub += ["ble_pub/prf/prf.c"]
    src_pub += ["ble_pub/prf/prf_utils.c"]
    src_pub += ["ble_pub/profiles/comm/src/comm.c"]
    src_pub += ["ble_pub/profiles/comm/src/comm_task.c"]
    src_pub += ["ble_pub/profiles/sdp/src/sdp_comm_task.c"]
    src_pub += ["ble_pub/profiles/sdp/src/sdp_common.c"]
    src_pub += ["ble_pub/app/src/app_comm.c"]
    src_pub += ["ble_pub/app/src/app_ble.c"]
    src_pub += ["ble_pub/app/src/app_task.c"]
    src_pub += ["ble_pub/app/src/app_ble_init.c"]
    src_pub += ["ble_pub/app/src/app_sdp.c"]
    src_pub += ["ble_pub/ui/ble_ui.c"]
    src_pub += ["platform/7231n/rwip/src/rwip.c"]
    src_pub += ["platform/7231n/rwip/src/rwble.c"]
    src_pub += ["platform/7231n/entry/ble_main.c"]
    src_pub += ["platform/7231n/driver/rf/rf_xvr.c"]
    src_pub += ["platform/7231n/driver/rf/ble_rf_port.c"]
    src_pub += ["platform/7231n/driver/uart/uart_ble.c"]

    path += [cwd + '/ble_lib/ip/ble/hl/api']
    path += [cwd + '/ble_lib/ip/ble/hl/inc']
    path += [cwd + '/ble_lib/ip/ble/hl/src/gap/gapc']
    path += [cwd + '/ble_lib/ip/ble/hl/src/gap/gapm']
    path += [cwd + '/ble_lib/ip/ble/hl/src/gatt']
    path += [cwd + '/ble_lib/ip/ble/hl/src/gatt/attc']
    path += [cwd + '/ble_lib/ip/ble/hl/src/gatt/attm']
    path += [cwd + '/ble_lib/ip/ble/hl/src/gatt/atts']
    path += [cwd + '/ble_lib/ip/ble/hl/src/gatt/gattc']
    path += [cwd + '/ble_lib/ip/ble/hl/src/gatt/gattm']
    path += [cwd + '/ble_lib/ip/ble/hl/src/l2c/l2cc']
    path += [cwd + '/ble_lib/ip/ble/hl/src/l2c/l2cm']
    path += [cwd + '/ble_lib/ip/ble/ll/api']
    path += [cwd + '/ble_lib/ip/ble/ll/import/reg']
    path += [cwd + '/ble_lib/ip/ble/ll/src']
    path += [cwd + '/ble_lib/ip/ble/ll/src/llc']
    path += [cwd + '/ble_lib/ip/ble/ll/src/lld']
    path += [cwd + '/ble_lib/ip/ble/ll/src/llm']
    path += [cwd + '/ble_lib/ip/em/api']
    path += [cwd + '/ble_lib/ip/hci/api']
    path += [cwd + '/ble_lib/ip/hci/src']
    path += [cwd + '/ble_lib/ip/sch/api']
    path += [cwd + '/ble_lib/ip/sch/import']
    path += [cwd + '/ble_lib/modules/aes/api']
    path += [cwd + '/ble_lib/modules/aes/src']
    path += [cwd + '/ble_lib/modules/common/api']
    path += [cwd + '/ble_lib/modules/dbg/api']
    path += [cwd + '/ble_lib/modules/dbg/src']
    path += [cwd + '/ble_lib/modules/ecc_p256/api']
    path += [cwd + '/ble_lib/modules/h4tl/api']
    path += [cwd + '/ble_lib/modules/ke/api']
    path += [cwd + '/ble_lib/modules/ke/src']
    path += [cwd + '/ble_pub/prf']
    path += [cwd + '/platform/7231n/rwip/api']
    path += [cwd + '/platform/7231n/rwip/import/reg']
    path += [cwd + '/platform/7231n/nvds/api']
    path += [cwd + '/platform/7231n/config']
    path += [cwd + '/platform/7231n/driver/reg']
    path += [cwd + '/platform/7231n/driver/rf']
    path += [cwd + '/platform/7231n/driver/uart']
    path += [cwd + '/platform/7231n/entry']
    path += [cwd + '/arch/armv5']
    path += [cwd + '/arch/armv5/ll']
    path += [cwd + '/arch/armv5/compiler']
    path += [cwd + '/ble_pub/profiles/comm/api']
    path += [cwd + '/ble_pub/profiles/sdp/api']
    path += [cwd + '/ble_pub/app/api']
    path += [cwd + '/ble_pub/ui']

libs = [ble_lib_name]
libpath = [cwd + '/']

if (platform_match == 'yes') and (GetLocalDepend(options, 'CFG_SUPPORT_BLE') == 1):
    print 'using ble_5_x: lib' + ble_lib_name + '.a'
    group_use_lib = DefineGroup('beken_ble_pub', src_pub, depend = [], CPPPATH = path, LIBS = libs, LIBPATH = libpath)
    group_build_lib = DefineGroup('beken_ble', src_lib, depend = ['BUILD_LIB'], CPPPATH = path, LIBS = libs, LIBPATH = libpath, LIBNAME = 'lib' + ble_lib_name + '.a')
    group = group_use_lib + group_build_lib
else:
    group = []

Return('group')
